public class Announcement_Update_Status {
      public Announcement_Update_Status(){}
      
      public Id Ann_Id{get; set;}
      public PageReference verifyParameters() {
        if (ApexPages.currentPage().getParameters().containsKey('paramAnn_Id')){
              Ann_Id = ApexPages.currentPage().getParameters().get('paramAnn_Id');
              Update_Status(Ann_Id);
       }  
        return null;
    }
      
 public static void Update_Status( Id Ann_c_Id) {//Ann_c_Id is a parameter
 // with Ann_c_Id get the related task 
        List <A_Task__c> lista_tareas = [SELECT Id, Status__c from A_Task__c where A_Task__c.Announcement__c = :Ann_c_Id];
        // lista_completa is a flag when we assume that all task are completed
        
        Boolean lista_completa = true;
        Boolean lista_inprogress = true;
        // During the loop reviews the list and if a task 
        // is incomplete then the flag changes to false 
        // and remains so until the end. 
        for (A_Task__c task_actual :lista_tareas)
        {
            System.Debug(task_actual.Status__c);
            if (task_actual.Status__c =='Not Started')
            {
                System.Debug('if (task_actual.Status__c==Not Started)');
                lista_completa = false;
                lista_inprogress = false;
            } else {
                    System.Debug('else (task_actual.Status__c==Not Started)');
                    if (task_actual.Status__c !='Completed' )
                    {
                        System.Debug('if (task_actual.Status__c!=Completed)');
                        lista_completa = false;
                    }
            }
        }
        // if flag 'lista_completa' is true then change the status 
        //of the announcement parent 
        if (lista_completa){
            System.Debug('if (lista_completa)');
            Announcement__c announcement_editable = [SELECT Id, Status__c from Announcement__c where Announcement__c.Id = :Ann_c_Id];            
            announcement_editable.Status__c = 'Completed';
            Database.update(announcement_editable);
        }else {
            System.Debug('else (lista_completa)');
            if (lista_inprogress){
                System.Debug('if (lista_inprogress)');
                Announcement__c announcement_editable = [SELECT Id, Status__c from Announcement__c where Announcement__c.Id = :Ann_c_Id];            
                announcement_editable.Status__c = 'In Progress';
                Database.update(announcement_editable);
            }
        } 
        
    }
}